 window.onload = function() {
    var regtel = /^1[3|4|5|7|8]\d{9}$/; //手机号码正则表达式
    var regqq = /[1-9][0-9]{4,}/;
    var regname = /^[\u4e00-\u9fa5]{2,9}$/;
    var regmes =/^\d{4,6}$/;
    var regpwd = /^[a-zA-Z]|\w{5,17}$/;

    var tel = document.querySelector('#tel');
    var qq = document.querySelector('#qq');
    var name = document.querySelector('#name');
    var mes = document.querySelector('#mes');
    var password = document.querySelector('#password'); 
    var surepwd = document.querySelector('#surepwd');

    regexp(tel, regtel);//手机号码
    regexp(qq, regqq);  //QQ号
    regexp(name,regname);//昵称
    regexp(mes,regmes);//短信验证
    regexp(password,regpwd);//密码
    //表单验证函数
    function regexp(ele,reg){
        ele.onblur = function() {
            if(reg.test(this.value)) {
                // console.log('正确');
                this.nextElementSibling.className = 'success';
                this.nextElementSibling.innerHTML = '<i class="success_icon"></i> 恭喜您输入正确';
            }else{ 
                // console.log('不正确');
                this.nextElementSibling.className = 'error';
                this.nextElementSibling.innerHTML = '<i class="error_icon"></i>格式不正确，请重新输入';
            }
        }
    };
    surepwd.onblur = function(){
        if(this.value==password.value){
            this.nextElementSibling.className = 'success';
            this.nextElementSibling.innerHTML = '<i class="success_icon"></i> 恭喜您输入正确';
        }else{
            this.nextElementSibling.className = 'error';
            this.nextElementSibling.innerHTML = '<i class="error_icon"></i>两次密码不一致';
        }
    }
 }  